<?php

/**
 * SiteController.php
 */
class SiteController extends CController {
    public $layout = 'login';


    public function actionLogin(){
        $model = new LoginForm;

        //check post
        if(isset($_POST['LoginForm'])){
            $model->attributes = $_POST['LoginForm'];

            //validate and login
            if($model->validate() && $model->login()){
                //redirect to backend
                $this->redirect(array('dashboard/index'));
            }else{
                //print_r($model->getErrors());
            }
        }
        $this->render('login', compact('model'));
    }

    /**
     * logout
     */
    public function actionLogout(){
        Yii::app()->user->logout();
        //redirect to home page
        $this->redirect(array('login'));
    }

}